<?php
/**
 * Created by PhpStorm.
 * User: hisheng
 * Date: 2017/6/8
 * Time: 14:58
 */
namespace App\Dao;

use App\Apply;
use App\Loan;
use App\User;

class ApplyDao
{
    public $apply;
    public $user;
    public $loan;
    
    public function __construct(Apply $apply , User $user ,Loan $loan)
    {
        $this->apply = $apply;
        $this->user = $user;
        $this->loan = $loan;
    }
    
    public function last(){
        $apply =  $this->apply->orderBy('created_at','desc')->first();
        $user = $this->user->find($apply->user_id);
        if(empty($user)){
            $user = $this->user;
            $user->id = 1;
            $user->name = '海生';
            $user->mobile = '15190290573';
        }
        $loan = $this->loan->find($apply->loan_id);
        $detail = [];
        $detail['user_id'] = $user->id;
        $detail['user_name'] = $user->name;
        $detail['user_mobile'] = $user->mobile;
    
        $detail['company_name'] = $loan->company_name;
        
        $detail['apply_amount'] = $apply->apply_amount;
        $detail['apply_time'] = $apply->apply_time;
        return $detail;
        
    }
}
